package com.ruoyi.ftrl.io.server.controller;




import com.ruoyi.ftrl.io.server.domain.BTypeCollector;
import com.ruoyi.ftrl.service.MessagePublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
public class RedisController {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    MessagePublisher messagePublisher;

    @PostMapping("/set")
    public void RedisDemo(@RequestBody BTypeCollector bTypeCollector) {
        System.out.println("bTypeCollector = " + bTypeCollector);
        redisTemplate.opsForValue().set("student", bTypeCollector);
    }

    @GetMapping("/get")
    public BTypeCollector get(String key) {
        return (BTypeCollector) redisTemplate.opsForValue().get(key);
    }


    /**
     * 指定频道号发布消息
     * @param message
     * @return
     */
    @PostMapping("/publish")
    public String publishMessage(@RequestParam String message) {
        messagePublisher.publish(message);
        return "指定频道号发布布消息成功！";
    }
}
